<template>
  <div class="activity">
    <div class="countDown" v-if="Object.keys(tourInfo).length">
      <count-down v-if="(tourInfo.status == 1 || tourInfo.status == 2) && tourInfo.timeDiff > 0" :time="tourInfo.timeDiff * 1000" @finish="countDownFinished">
        <template #default="timeData">
          <span class="icon"></span>
          <span class="colon" v-show="tourInfo.status == 1">开始倒计时:</span>
          <span class="colon" v-show="tourInfo.status == 2">结束倒计时:</span>
          <span class="block">{{ timeData.days }}</span>
          <span class="colon">天</span>
          <span class="block">{{ timeData.hours }}</span>
          <span class="colon">时</span>
          <span class="block">{{ timeData.minutes }}</span>
          <span class="colon">分</span>
          <span class="block">{{ timeData.seconds }}</span>
          <span class="colon">秒</span>
        </template>
      </count-down>
      <p v-else>活动已结束</p>
    </div>
    <div class="pageTitle">
      <h2 class="title"></h2>
      <!-- <h2 class="city">{{tourInfo.city || ''}}</h2> -->
      <h2 class="city" :style="`background: url(${getCityName(tourInfo.stationId)}) no-repeat; background-size: contain`"></h2>
      <p>巡展现场宝迷专享</p>
    </div>
    <div class="tequan tequan_1">
      <div class="title">
        <p>现场特权1：</p>
        <span>宝姐珠宝所有正价商品折上折</span>
      </div>
      <div class="discountWrap">
        <div class="newDiscount">
          <h3>{{tourInfo.newDiscount || ''}}<span>折</span></h3>
        </div>
        <div class="discount">
          <div class="currentDiscount">
            <h3>{{tourInfo.discount || ''}}<span>折</span></h3>
            <p>您的会员折扣</p>
          </div>
          <div class="currentDiscount">
            <h3>{{tourInfo.discount || ''}}<span>折</span></h3>
            <p>您的会员折扣</p>
          </div>
        </div>
        <div class="lineWrap">
          <div class="lineText before">巡展前</div>
          <div class="lineText now">巡展期间</div>
          <div class="lineText after">巡展结束</div>
        </div>
      </div>
    </div>
    <div class="tequan tequan_2">
      <div class="title">
        <p>现场特权2：</p>
        <span>优选珠宝特价购</span>
      </div>
      <div class="goodsList">
        <div class="goods" v-for="n in goodsList" :key="n.goods_id" @click="buyThis(n)">
          <div class="goodsImg">
            <img :src="n.original_img" alt="">
          </div>
          <div class="googdsInfo">
            <div class="goodsName">
              <p class="tips">特价</p>
              <p class="name">{{n.goods_name}}</p>
            </div>
            <div class="activityPrice">
              <p class="text">现场特价￥</p>
              <p>{{n.shop_price}}</p>
            </div>
            <div class="info">
              <div class="oldPrice">
                <p>市场价：</p><p class="deleteLine">{{n.market_price}}</p>
              </div>
              <div v-if="n.store_count > 0" class="counts">限量{{n.store_count}}件</div>
            </div>
            <div v-if="n.store_count > 0" class="buyBtn">立即抢购 ></div>
            <div @click.stop="() => {}" v-else class="buyBtn buyBtn_over">已售罄</div>
          </div>
        </div>
      </div>
    </div>
    <overlay :lock-scroll="true" z-index="1001" :show="maskState && isLoading" />
    <loading type="spinner" v-show="isLoading" class="loading"  size="24px">加载中...</loading>
  </div>
</template>

<script>
import { mapState } from "vuex";
import {getTourGoodsList} from '@/api/request'
import { CountDown, Overlay, Loading } from 'vant'
export default {
  name: 'Activity',
  data () {
    return {
      requestFrom: 'userCenter',
      tourInfo: {},
      goodsList: [],
      cityList: [
        {
          id: 34,
          url: require('../assets/images/cd.png')
        }, {
          id: 29,
          url: require('../assets/images/sy.png')
        }, {
          id: 31,
          url: require('../assets/images/hz.png')
        }, {
          id: 35,
          url: require('../assets/images/nj.png')
        }, {
          id: 32,
          url: require('../assets/images/sh.png')
        }, {
          id: 30,
          url: require('../assets/images/bj.png')
        }, {
          id: 28,
          url: require('../assets/images/gz.png')
        }
      ]
    }
  },
  components: {
    CountDown, Overlay,Loading
  },
  computed: mapState({
    maskState: state => {
      console.log(state)
      return state.maskState;
    },
    unionKey: state => {
      return state.unionKey
    },
    token: state => {
      return state.token
    },
    isLoading: state => {
      return state.isLoading
    }
  }),
  mounted () {
    this.getTourGoodsList()
  },
  methods: {
    getCityName (id) {
      let arr = this.cityList.filter(val => {
        if (val.id == id) {
          return val
        }
      })
      if (arr.length > 0) {
        return arr[0].url
      }
      console.log(arr)
    },
    buyThis (n) {
      window.WebViewJavascriptBridge && window.WebViewJavascriptBridge.callHandler('goGoodsDetail', {
        goods_id: n.goods_id,
        activity_id: n.activity_id
      })
    },
    webViewFunc (funcName, callback) {
      window.WebViewJavascriptBridge && window.WebViewJavascriptBridge.registerHandler(funcName, callback)
    },
    countDownFinished () {
      this.getTourGoodsList()
    },
    getTourGoodsList () {
      getTourGoodsList({
        unionKey: this.unionKey,
        token: this.token,
        requestFrom: this.requestFrom
      }).then(res => {
        console.log(res)
        if (res.data.goodsList) {
          this.goodsList = res.data.goodsList
        }
        this.tourInfo = res.data.common
      }).catch(e => {
        console.log(e)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  .loading{
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 1002;
    transform: translate(-50%, -50%);
  }
  .activity{
    padding-top: calc(constant(safe-area-inset-top) + 44px); /* 兼容 iOS < 11.2 */
    padding-top: calc(env(safe-area-inset-top) + 44px);
    padding-bottom: 1rem;
    position: relative;
    width: 100%;
    min-height: 100vh;
    background: url(../assets/images/bg.jpg) no-repeat;
    background-size: cover;
    overflow: hidden;

    .countDown{
      position: fixed;
      left: 0;
      right: 0;
      height: 0.7rem;
      display: flex;
      font-size: 14px;
      color: #000;
      justify-content: center;
      background-color: #4865FC;
      z-index: 10;
      >p{
        font-size: 0.3rem;
        color: #fff;
        font-weight: 600;
        line-height: 0.7rem;
      }
      .van-count-down{
        display: flex;
        align-items: center;
      }
      .icon{
        display: inline-block;
        width: 0.29rem;
        height: 0.29rem;
        background: url(../assets/images/clock.png) no-repeat;
        background-size: contain;
        margin-right: 0.2rem;
        transform-origin: center bottom;
        animation: clock 3s linear infinite;
      }
      @keyframes clock {
        0%{
          transform: rotate(-0deg);
        }
        8%{
          transform: rotate(-10deg);
        }
        16%{
          transform: rotate(10deg);
        }
        24%{
          transform: rotate(-10deg);
        }
        32%{
          transform: rotate(10deg);
        }
        40%{
          transform: rotate(0deg);
        }
        100%{
          transform: rotate(0);
        }
      }
      .colon{
        min-width: 0.3rem;
        font-size: 0.3rem;
        color: #fff;
        font-weight: 600;
      }
      .block{
        min-width: 0.4rem;
        display: inline-block;
        text-align: center;
        color: #FFFF3E;
        line-height: 0.7rem;
        font-size: 0.3rem;
        font-weight: 600;
      }
    }
    .pageTitle{
      width: 100%;
      text-align: center;
      padding: 0.6rem 0 0.5rem;
      margin-top: 0.7rem;
      .title{
        width: 4.12rem;
        height: 0.45rem;
        margin: 0 auto 0.38rem;
        background: url(../assets/images/title.png) no-repeat;
        background-size: contain;
      }
      .city{
        width: 1.36rem;
        height: 0.44rem;
        margin: 0 auto 0.27rem;
      }
      p{
        font-size: 0.41rem;
        color: #173467;
        font-weight: 500;
      }
    }
    .tequan{
      margin: 0 0.3rem;
      border-radius: 20px;
      padding: 0.4rem 0.34rem;

      .title{
        display: flex;
        font-weight: 500;
        font-size: 0.3rem;
        p{
          color: #EE0027;
        }
        span{
          color: #000;
        }
      }
    }
    .tequan_1{
      margin-bottom: 0.5rem;
      background: #fff;

      .discountWrap{
        position: relative;
        margin: 0.44rem auto 0;
        background: url(../assets/images/discount_2.png) no-repeat;
        background-size: 2.29rem 2rem;
        background-position: center 0.42rem;
        .newDiscount{
          position: absolute;
          top: 0.82rem;
          left: 0;
          right: 0;
          margin: auto;
          text-align: center;

          h3{
            font-size: 0.6rem;
            color: #fff;

            span{
              font-size: 0.46rem;
            }
          }
        }
        .discount{
          width: 6rem;
          margin: 0 auto;
          display: flex;
          justify-content: space-between;

          .currentDiscount{
            h3{
              color: #1DA3FB;
              font-size: 0.5rem;
              line-height: 1;
              text-align: center;

              span{
                font-size: 0.39rem;
              }
            }
            p{
              font-size: 0.15rem;
              text-align: center;
              color: #000000;
            }
          }
        }
        .lineWrap{
          width: 4.95rem;
          height: 2.54rem;
          background: url(../assets/images/discount_1.png) no-repeat;
          background-size: contain;
          margin: 0 auto;
          position: relative;

          .lineText{
            font-size: 0.2rem;
            color: #000;
            font-weight: 500;
          }
          .before{
            position: absolute;
            top: 0.58rem;
            left: -0.2rem;
          }
          .now{
            position: absolute;
            bottom: -0.2rem;
            left: 50%;
            transform: translateX(-50%);
          }
          .after{
            position: absolute;
            top: 0.58rem;
            right: -0.4rem;
          }
        }
      }
      
    }
    .tequan_2{
      padding: 0;
      .goodsList{
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        margin-top: 0.35rem;

        .goods{
          width: 3.4rem;
          background: #FFFFFF;
          border-radius: 10px;
          margin-bottom: 0.1rem;
          overflow: hidden;

          .goodsImg{
            width: 3.4rem;
            height: 3.4rem;
            img{
              width: 100%;
              height: 100%;
            }
          }
          .googdsInfo{
            padding: 0.2rem 0.14rem 0.32rem;
          }
          .goodsName{
            display: flex;
            align-items: center;

            .tips{
              background: #EE0027;
              font-size: 0.2rem;
              color: #fff;
              text-align: center;
              line-height: 0.3rem;
              border-radius: 2px;
              padding: 0 0.05rem;
              margin-right: 0.1rem;
            }
            .name{
              flex: 1;
              font-size: 0.3rem;
              color: #383838;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              font-weight: 500;
            }
          }
          .activityPrice{
            display: flex;
            line-height: 0.56rem;
            p{
              font-size: 0.4rem;
              color: #EE0027;
            }
            .text{
              font-size: 0.24rem;
              color: #EE0027;
            }
          }
          .info{
            display: flex;
            justify-content: space-between;
            font-size: 0.24rem;
            color: #999999;

            .oldPrice{
              display: flex;
            }
            .deleteLine{
              text-decoration: line-through;
            }
          }
          .buyBtn{
            width: 2.4rem;
            height: 0.54rem;
            background: url(../assets/images/buyBtn.png) no-repeat;
            background-size: contain;
            font-size: 0.28rem;
            text-align: center;
            line-height: 0.54rem;
            color: #fff;
            margin: 0.26rem auto 0;
            border-radius: 0.27rem;
          }
          .buyBtn_over{
            background: #d5d5d5;
          }
        }
      }
    }
  }
</style>